const { exec } = require('../db/index');
const jwt = require('jsonwebtoken')
class HomeService {
  async login(ctx) {
    const { username, password } = ctx.request.body;
    const data = await exec(`select * from users where username=? and password=?`,
      [username, password])
    if (data.length) {
      let token = jwt.sign({ ...data[0] }, 'kkk', { expiresIn: '24h' })
      return { code: 0, msg: 'success', token }
    } else {
      return { code: -1, msg: 'fail' }
    }
  }
  async register(ctx) {

  }
}

module.exports = new HomeService